using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter07
{
	/// <summary>
	/// Example09: Block Pulled on a Rough Surface
	/// A 6.0 kg block initially at rest is pulled to the right 
	/// along a horizontal surface by a constant horizontal 
	/// force of 12 N.
	/// (A) Find the speed of the block after it has moved 3.0 m 
	/// if the surfaces in contact have a coefficient of kinetic 
	/// friction of 0.15. (This is Example 7.7, modified so that 
	/// the surface is no longer frictionless)
	/// v_f = 1.8 m/s
	/// (B) Suppose the force F is applied at an angle \theta as
	/// shown in Figure 7.18b. At what angle should the force be
	/// applied to achieve the largest possible speed after the
	/// block has moved 3.0 m to the right?
	/// \theta = 8.5^{\circle}
	/// </summary>
	public class Example09
	{
		public Example09()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Mass m = new L.Mass();
			m.kg = 6.0;
			//(A)
			L.Force f = new L.Force();
			f.X = 12.0;
			L.Displacement d = new L.Displacement();
			d.X = 3.0;
			L.Force friction = new L.Force();
			friction.X = - 0.15*m.kg*L.Constant.AccelerationOfGravity;
            L.Work[] W = new L.Work[2];
			W[0] = new L.Work(f,d);
			W[1] = new L.Work(friction,d);
			L.KineticEnergy ki = new L.KineticEnergy();
			ki.J = 0.0;
			L.KineticEnergy kf = new L.KineticEnergy();
			kf.VariableQ = true;
	    	L.FundamentalLaw.WorkEnergyTheorem(ki,W,kf);
			L.Velocity vf = new L.Velocity(m,kf);
			result += Convert.ToString(vf.Norm)+"\r\n";
			//(B)
			double theta = 0.0;
			for(int step = 0; step < 100; step++)
			{	
				theta = 0.1*(double)step;
				L.Force fB = new L.Force();
				fB.X = 12.0*Math.Cos(theta/180.0*Math.PI);
				fB.Y = 12.0*Math.Sin(theta/180.0*Math.PI);
				L.Force frictionB = new L.Force();
				frictionB.X = - 0.15
					*(m.kg*L.Constant.AccelerationOfGravity-fB.Y);
				L.Work[] WB = new L.Work[2];
				WB[0] = new L.Work(fB,d);
				WB[1] = new L.Work(frictionB,d);
		        L.KineticEnergy kfB = new L.KineticEnergy();
				kfB.VariableQ = true;
				L.FundamentalLaw.WorkEnergyTheorem(ki,WB,kfB);
				L.Velocity vfB = new L.Velocity(m,kfB);
				result += Convert.ToString(theta)+"  "
					+Convert.ToString(vfB.Norm)+"\r\n";
			}
		}
	}
}
